/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Model;

import Helper.PatientHelper;
import common.Constant;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;




/**
 *
 * @author hxbien
 */
public class PatientModel extends AbstractTableModel{

    ClassLoader c = this.getClass().getClassLoader();

    ArrayList<PatientHelper> PatientList;
    private final String colunmsName[] = { Constant.getBundle().getString("patientID"), Constant.getBundle().getString("patientName"),Constant.getBundle().getString("patientAddress"), Constant.getBundle().getString("patientGender"),Constant.getBundle().getString("age"), Constant.getBundle().getString("patientPhone"),Constant.getBundle().getString("description") };
    private final Class columnsClass[] = { String.class, String.class,String.class, String.class,String.class, String.class,String.class };

    public PatientModel(ArrayList<PatientHelper> PatientList){
        this.PatientList = PatientList;
    }
    @Override
    public int getRowCount() {
         return PatientList.toArray().length;
    }

    @Override
    public int getColumnCount() {
         return colunmsName.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch(columnIndex){
            case 0 :
                return PatientList.get(rowIndex).getPatientId();
            case 1 :
                return PatientList.get(rowIndex).getPatientName();
            case 2 :
                return PatientList.get(rowIndex).getPatientAddress();
            case 3 :
                return PatientList.get(rowIndex).getPatientGender();
            case 4 :
                return PatientList.get(rowIndex).getPatientAge();
            case 5 :
                return PatientList.get(rowIndex).getPatientPhone();
            case 6 :
                return PatientList.get(rowIndex).getPatientDescription();
            default : return null;
        }
    }

     @Override
    public void setValueAt(Object val, int rowIndex, int columnIndex) {
    if(columnIndex==0)
            PatientList.get(rowIndex).setCheck(Boolean.parseBoolean(val.toString()));
        fireTableRowsUpdated(rowIndex, rowIndex);
    }
      @Override
    public String getColumnName(int icol){
        return colunmsName[icol];
    }

    @Override
    public Class getColumnClass(int icol){
        return columnsClass[icol];
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return columnIndex == 0;
    }


     public void deleteRow(int deleteRow) {
        PatientList.remove(deleteRow);
        PatientList.trimToSize();
        fireTableRowsDeleted(deleteRow, deleteRow);
    }
    
}
